var ctx = ctx;
var patientId=$("#patientId").val();
var patVisitId=$("#patVisitId").val();
var bedId=$("#bedRecId").val();
$(function(){
    var bedId = $('#bedRecId').val();
   // loadDiv('turnInPatientListDiv',ctx+'/nurse/wardCirculation/findWaitCancelTurnInPatientList?bedRecId='+bedId);
    return loadDiv('cancelTurnInForm',ctx+'/nurse/wardCirculation/findInfoByCancelTurnInParam?patientId='+patientId+'&patVisitId='+patVisitId+'&bedRecId='+bedId);
});

function showCancelTurnInForm(patientId,patVisitId){
    var bedId = $('#bedRecId').val();
    $("#turnInPatientListDiv").attr("class","col-lg-8");
    hideShowTableTd("turnInPatientListDiv", '3,4,5', '2');
    $("#cancelTurnInForm").show('normal');
    return loadDiv('cancelTurnInForm',ctx+'/nurse/wardCirculation/findInfoByCancelTurnInParam?patientId='+patientId+'&patVisitId='+patVisitId+'&bedRecId='+bedId);
}

function closeTurnInForm(){
    $("#turnInPatientListDiv").attr("class","col-lg-12");
    $("#turnInPatientListDiv").show('normal');
    hideShowTableTd("turnInPatientListDiv", '3,4,5', '1');
    $("#cancelTurnInForm").attr("style","display: none");
}


function formSaveCancelTurnInLoad(divId,formId,url,hrefUrl,patientId,visitId){
    if(flag){
        /*判断病人是否有包床，如果有包床，解除包床后再取消移入*/
        $.ajax({
            type: "POST",
            url: ctx+"/nurse/bedRec/validBedOccupy?patientId="+patientId+"&visitId="+visitId,
            dataType: "json",
            success: function (data) {
                if (data.code == "success") {
                    if ($('#' + formId).parsley().validate()) {
                        flag=false;
                        $("#"+formId+" input,#"+formId+" select").removeAttr("disabled");
                        $.ajax({
                            type: "POST",
                            data:$("#"+formId).serialize(),
                            url: url,
                            dataType: "json",
                            success: function(data) {
                                // alert(data.code);
                                if (data.code == "1" || data.code==1) {
                                    if (data.data!=null&&data.data!=''){
                                        var datas = eval(data.data);
                                        for (var i = 0; i < datas.length; i++) {
                                            if (datas[i].results == "1") {
                                                toastr.info(datas[i].message);
                                            }
                                        }
                                    }
                                }else if(data.code==0 || data.code=='0'){
                                    toastr.success('取消移入病人病历成功');
                                    parent.layer.closeAll(); //关闭当前弹层
                                    parent.refesh();
                                }else {
                                    flag=true;
                                    toastr.error(data.data);
                                }
                            },
                            error: function(data) {
                                toastr.error('网络连接错误,请检查网络');
                                flag=true;
                            }
                        });
                    }
                } else if (data.code == "info") {
                    toastr.info(data.data);
                } else {
                    toastr.error('取消移入病人病历失败');
                }
            },
            error: function (data) {
                toastr.error('网络连接错误,请检查网络');
            }
        });

    }
    return false;
}